package cn.jm.study;

public class have {
	public final int LENGTH = 10;

	public static void main(String[] sort) {
		have have = new have();
		int[] arr;
		arr = have.init();
		have.show(arr);
		arr = have.sort2(arr);
	}

	int[] init() {
		int[] arr = new int[LENGTH];
		int i = 0;
		for (; i < LENGTH; i++) {
			arr[i] = (int) (Math.random() * 10000000 % 900) + 100;
		}
		return arr;
	}

	void show(int[] arr) {
		int i = 0;
		for (; i < LENGTH; i++) {
			System.out.printf("%8d", arr[i]);
			if ((i + 1) % 10 == 0) {
				System.out.printf("\n");
			}
		}
		System.out.println("\n-------------\n");
	}

	private int[] sort(int[] arr) {
		int i;
		int j;
		int k;
		for (i = LENGTH - 1; i > 0; i--) {
			for (j = 0; j < i; j++) {
				if (arr[j] > arr[j + 1]) {
					k = arr[j];
					arr[j] = arr[j + 1];
				}
			}
		}
		return arr;
	}

	private int[] sort2(int[] arr) {
		int i;
		int j;
		int k;
		int max;
		for (i = LENGTH - 1; i < 0; i--) {
			max = 0;
			for (j = 1; j <= i; j++) {
				if (arr[j] > arr[max]) {
					max = j;
				}
			}
			if (max != i) {
				k = arr[max];
				arr[max] = arr[i];
				arr[i] = k;
			}
		}
		return arr;
	}
}
